from typing import Optional
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy_crud_plus import CRUDPlus

from modules.{{ app_name }}.models.{{ filename }}_model import {{ class_name }}
from modules.{{ app_name }}.schemas.{{ filename }}_schema import {{ class_name }}Create, {{ class_name }}Update
from modules.{{ app_name }}.params.{{ filename }}_params import {{ class_name }}Query


class {{ class_name }}Repository(CRUDPlus[{{ class_name }}]):

    async def get_by_id(self, db: AsyncSession, pk: int):
        return await self.select_model_by_column(db, id=pk)

    async def create(self, db: AsyncSession, data: {{ class_name }}Create) -> {{ class_name }}:
        return await self.create_model(db, data)

    async def update(self, db: AsyncSession, pk: int, data: {{ class_name }}Update) -> Optional[{{ class_name }}]:
        await self.update_model(db, pk, data)
        return await self.select_model(db, pk)

    async def delete(self, db: AsyncSession, pk: int) -> bool:
        return await self.delete_model(db, pk)


{{ filename }}_dao = {{ class_name }}Repository({{ class_name }})